package com.zbf.auth.dao;

import com.zbf.auth.user.Menu;
import com.zbf.auth.user.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.Map;
import java.util.List;

/**
 * 作者: LCG
 * 日期: 2020/5/31 17:56
 * 描述:
 */
public interface UserDao extends JpaRepository<User,Long> {


    public User findByLoginNameIs(String loginName);

    /**
     * 获取用户所有的而角色
     * @param userId
     * @return
     */
    @Query(value = "select bur.role_id from base_user_role bur where bur.user_id= :userId",nativeQuery = true)
    public List<Long> getUserRole(@Param("userId") Long userId);


    /**
     * 更新用户的激活状态，激活用户
     */
    @Query(value = "update base_user set active=1 where id=:userId",nativeQuery = true)
    @Modifying
    @Transactional
    public void toUpdateUserActive(@Param("userId") Long userId);
}
